


#pragma once

#include <iostream>
#include <string>
#include <ctime>
#include <iomanip>  // 用于格式化输出
#include <time.h>
#include <stdarg.h>
#include <unistd.h>
#include <stdlib.h>
using namespace std;

#define Info 0
#define Debug 1
#define Warning 2
//#define Error 3
#define Fatal 4

#define LOG(LEVEL, MESSAGE) log(#LEVEL, MESSAGE, __FILE__, __LINE__)

void log(const string& level, const string& message, const string& file, int line)
{
    cout << "[" << level << "] ";
    time_t t = time(nullptr);
    struct tm *ctime = localtime(&t);
    char leftbuffer[1024];
    snprintf(leftbuffer, sizeof(leftbuffer), "[%d:%d:%d]",ctime->tm_hour, ctime->tm_min, ctime->tm_sec);

    // 输出日志信息
    cout << "[" << message << "] "<<leftbuffer ;

    cout << "[" << file << " : " << line << "]" << endl;
}




/*
#include <iostream>
#include <string>
#include <ctime>
#include <iomanip>  // 用于格式化输出
using namespace std;

#define Info 0
#define Debug 1
#define Warning 2
#define Error 3
#define Fatal 4

#define LOG(LEVEL, MESSAGE) log(#LEVEL, MESSAGE, __FILE__, __LINE__)

void log(string level, string message, string file, int line)
{
    cout << "[" << level << "]" ;
    time_t t = time(nullptr);
    struct tm *ctime = localtime(&t);
    char leftbuffer[1024];
    snprintf(leftbuffer, sizeof(leftbuffer), "[%d:%d:%d]", ctime->tm_hour, ctime->tm_min, ctime->tm_sec);
    cout<< "[" << message << "]" << "[" << file << " : " << line << "]" << endl;
}

*/

